<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\date\DatePicker;
use yii\helpers\ArrayHelper;
$yey = \app\models\School::find()->all();
$bj = \app\models\Classname::find()->all();
$ls = \app\models\Users::find()->all();
$js = <<<JS
//监听手机号学生出生日期 事件

 $("#student-xs_birth").change(function(){
   var dat  = $(this).val();
   var age =  dat.substr(0,4); //获取学生出生年份
    age = parseInt(age);
   //获取当前年份
   var myDate = new Date();
   var n = myDate.getFullYear(); 
     if(n==age){
        $("#student-xs_age").val(0.5); 
         return;
     }
   $("#student-xs_age").val(n-age);
  });
JS;
$this->registerJs($js);



/* @var $this yii\web\View */
/* @var $model app\models\Student */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="student-form">
    <?php
    if ($model->hasErrors()) {
        \yii\bootstrap\Alert::begin(
            [
                'options' => [
                    'class' => 'alert-warning',
                ]
            ]
        );
        echo Html::errorSummary($model);
        \yii\bootstrap\Alert::end();
    }
    ?>

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'xs_name')->textInput(['maxlength' => true]) ?>
    <?= $form->field($model, 'xs_xb')->radioList(['男'=>'男','女'=>'女'])?>

    <?= $form->field($model, 'xs_xm')->textInput() ?>
    <?= $form->field($model, 'xs_birth')->widget(DatePicker::classname(), [
        'options' => ['placeholder' => ''],
        'pluginOptions' => [
            'autoclose' => true,
            'todayHighlight' => true,
            'format' => 'yyyy-mm-dd',
        ]
    ]); ?>
    <?= $form->field($model, 'xs_age')->textInput() ?>
    <?= $form->field($model, 'xs_dad')->textInput() ?>
    <?= $form->field($model, 'xs_mm')->textInput() ?>
    <?= $form->field($model, 'xs_qs')->textInput() ?>



    <?= $form->field($model, 'xs_height')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'xs_weight')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'yey_id')->dropDownList(ArrayHelper::map($yey,'yey_id','yey_mingcheng')) ?>

    <?= $form->field($model, 'bj_id')->dropDownList(ArrayHelper::map($bj,'class_id','class_name')) ?>

    <?= $form->field($model, 'ls_id')->dropDownList(ArrayHelper::map($ls,'gl_id','gl_username')) ?>

  
	<?php if (!Yii::$app->request->isAjax){ ?>
	  	<div class="form-group">
	        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
	    </div>
	<?php } ?>

    <?php ActiveForm::end(); ?>
    
</div>
